import * as config from '../config'
const rolesList = []
const gjList=[]
const ossUploadUrl = 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/';
const chooseImage = {
	count: '1',
	sizeType: ['original', 'compressed'],
	sourceType: ['album'],
}
const imgType = '请选择图片来源'
const imgTypeList = [{
		name: '相册',
	},
	{
		name: '拍照',
	}
]
const makeValidityPeriod = function(type,yearnum) {
	console.log(yearnum)
	//获取当前年
	let nowDate = new Date();
	let year = nowDate.getFullYear()
	let _list = []
	let _list1 = []
	// let _list2 = ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]
	let _list2 = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
	let _list3 = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14",
		"15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
		"31"
	]
	let _ValidityPeriod = []
	if(yearnum){
		var len=year-Number(yearnum)
		var len2=30+len
		for (let i = 0; i < len2; i++) {
			_list1.push(yearnum + i)
		}
	}else{
		for (let i = 0; i < 30; i++) {
			_list1.push(year + i)
		}
	}
	
	if (type == 0) {
		_list1.unshift('长期')
		_list2.unshift('')
		_list3.unshift('')
	}
	_list.push(_list1, _list2, _list3)
	return _list
}

const getListByUserId = function() {
	let baseUrlNew = config.def().baseUrlNew
	var userInfo = uni.getStorageSync("userInfo")
	if (userInfo) {
		uni.request({
			url: baseUrlNew + '/roleMenu/query/getListByUserId',
			data: {
				userId: userInfo.id ? userInfo.id : userInfo.data.id
			},
			method: 'GET',
			success: (res) => {
				if (res.statusCode === 200) {
					uni.setStorageSync("jurisdiction", res.data.data)
					let list = getUserAllRoles(res.data.data);
					uni.setStorageSync("rolesList", list)
				}
			}
		})
	}
}
const getUserAllRoles = (item) => {
	console.log(item)

	for (let i = 0; i < item.length; i++) {
		rolesList.push(item[i].name)
		// console.log('用户权限',rolesList)
		if (item[i].children && item[i].children.length > 0) {
			getUserAllRoles(item[i].children)
		}
	}
	return rolesList;
}
const setAudit = (item) => {
	let _list = uni.getStorageSync("copyTaskInfo")
	let _isShowbtn = true
	if (_list.length == 0) {
		_isShowbtn = false
	}
	for (let i = 0; i < _list.length; i++) {
		if (_list[i].businessId == item.id) {
			_list.splice(i, 1)
			uni.setStorageSync("copyTaskInfo", _list)
		}
	}
	if (_list.length > 0) {
		uni.navigateTo({
			url: _list[0].itemUrl + '&isShowbtn=' + _isShowbtn,
		})
	}
	console.log(item)
}
const contactCustomerService = (phone) => {
	console.log(phone)
	//客服
	if (!phone) {
		phone = '10086'
	}
	const res = uni.getSystemInfoSync();
	// ios系统默认有个模态框
	if(res.platform=='ios'){
		uni.makePhoneCall({
		phoneNumber:phone,
		success(){
			console.log('拨打成功了');
		},
		fail() {
			console.log('拨打失败了');
		}
	})
	}else{
	//安卓手机手动设置一个showActionSheet
		uni.showActionSheet({
			itemList: [phone,'呼叫'],
			success:function(res){
				console.log(res);
			   if(res.tapIndex==1){
				uni.makePhoneCall({
				  phoneNumber: phone,
				success: (res) => {
					console.log('调用成功!')
					
				},
			  
				// 失败回调
				fail: (res) => {
					console.log('调用失败!')
					// contactCustomerService(item)
				}
				})
			  }
			}
		  })
	}
	// console.log("联系客服")
	// uni.makePhoneCall({
	// 	phoneNumber: item,
	// 	success: (res) => {
	// 		console.log('调用成功!')
	// 	},

	// 	// 失败回调
	// 	fail: (res) => {
	// 		console.log('调用失败!')
	// 		contactCustomerService(item)
	// 	}
	// });
}


export default {
	getListByUserId,
	setAudit,
	ossUploadUrl,
	contactCustomerService,
	chooseImage,
	imgType,
	imgTypeList,
	makeValidityPeriod,
	gjList
}
